package com.appbee.songs.server;

import java.io.IOException;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Singleton;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.appbee.songs.server.dao.SongDAO;
import com.appbee.songs.server.model.Song;

@Singleton
public class FixSongIndex extends HttpServlet
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private final SongDAO songDAO;

	@Inject
	public FixSongIndex(SongDAO songDAO)
	{
		this.songDAO = songDAO;

	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		List<Song> list = songDAO.findByRange(0, 100);
		for (int i = 0; i < list.size(); i++)
		{
			Song song = list.get(i);
			song.setNumber(i + 1);
			songDAO.updateWithOutUserAndTimestamp(song);
		}
		resp.getWriter().println("<p>done</p>");
	}

}
